<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="220px">
      <el-form-item label="网站标题">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="网站标题后缀">
        <el-input v-model="form.title_suffix" />
      </el-form-item>
      <el-form-item label="网站关键词">
        <el-input v-model="form.keywords" type="textarea" />
      </el-form-item>
      <el-form-item label="网站描述">
        <el-input v-model="form.description" type="textarea" />
      </el-form-item>
      <el-form-item label="商品售价与1688价格比例(单位%，默认300)">
        <el-col :span="4">
          <el-input v-model="form.alibaba_price" />
        </el-col>
      </el-form-item>
      <el-form-item label="退款、退货服务费率(单位%,默认20)">
        <el-col :span="4">
          <el-input v-model="form.service_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="晒单会员获得金豆数">
        <el-col :span="4">
          <el-input v-model="form.tbk_rebate_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="晒单会员上级所得金豆比例">
        <el-col :span="4">
          <el-input v-model="form.tbk_parent_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="晒单会员上上级所得金豆比例">
        <el-col :span="4">
          <el-input v-model="form.tbk_sub_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团失败用户的返利比例(单位:%,默认40%)">
        <el-col :span="4">
          <el-input v-model="form.rebate_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团失败会员的上级所得金豆比例(单位:%,默认15%)">
        <el-col :span="4">
          <el-input v-model="form.parent_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团失败会员的上上级所得金豆比例(单位:%,默认10%)">
        <el-col :span="4">
          <el-input v-model="form.sub_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="兑换商品所需的积分与商品价格的比例(单位%,默认1000%)">
        <el-col :span="4">
          <el-input v-model="form.exchange_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="基础运费(单位:元,默认:6)">
        <el-col :span="4">
          <el-input v-model="form.default_post_fee" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团等待时间(单位秒,默认10分钟)">
        <el-col :span="4">
          <el-input v-model="form.coupon_expire" />
        </el-col>
      </el-form-item>
      <el-form-item label="向1688支付的等待时间(单位:秒,默认600)">
        <el-col :span="4">
          <el-input v-model="form.coupon_delay" />
        </el-col>
      </el-form-item>
      <el-form-item label="机器人参与评团时的胜率(单位:%,默认30%)">
        <el-col :span="4">
          <el-input v-model="form.coupon_bot_rate" />
        </el-col>
      </el-form-item>
      <el-form-item label="新用户首次拼单买不到商品(默认关闭)">
        <el-select v-model="form.userwin" class="filter-item" placeholder="请选择状态">
          <el-option label="关闭" value="0" />
          <el-option label="开启" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="新用户首次拼单返现余额(单位:元,默认0.00,不返现)">
        <el-col :span="4">
          <el-input v-model="form.userback" />
        </el-col>
      </el-form-item>
      <el-form-item label="iOS下载地址">
        <el-col :span="4">
          <el-input v-model="form.download_iOS" />
        </el-col>
      </el-form-item>
      <el-form-item label="安卓下载地址">
        <el-col :span="4">
          <el-input v-model="form.download_Android" />
        </el-col>
      </el-form-item>
      <el-form-item label="关于我们url">
        <el-col :span="4">
          <el-input v-model="form.about_us" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团协议url">
        <el-col :span="4">
          <el-input v-model="form.coupon_protocol" />
        </el-col>
      </el-form-item>
      <el-form-item label="退款协议url">
        <el-col :span="4">
          <el-input v-model="form.refund_protocol" />
        </el-col>
      </el-form-item>
      <el-form-item label="退货协议url">
        <el-col :span="4">
          <el-input v-model="form.return_protocol" />
        </el-col>
      </el-form-item>
      <el-form-item label="客服链接">
        <el-col :span="4">
          <el-input v-model="form.customer_service" />
        </el-col>
      </el-form-item>
      <el-form-item label="客服qq">
        <el-col :span="4">
          <el-input v-model="form.customer_qq" />
        </el-col>
      </el-form-item>
      <el-form-item label="客服微信">
        <el-col :span="4">
          <el-input v-model="form.customer_wechat" />
        </el-col>
      </el-form-item>
      <el-form-item label="建议url">
        <el-col :span="4">
          <el-input v-model="form.advance" />
        </el-col>
      </el-form-item>
      <el-form-item label="帮助的url">
        <el-col :span="4">
          <el-input v-model="form.help" />
        </el-col>
      </el-form-item>
      <el-form-item label="订单说明的url">
        <el-col :span="4">
          <el-input v-model="form.order_info" />
        </el-col>
      </el-form-item>
      <el-form-item label="注册协议的url">
        <el-col :span="4">
          <el-input v-model="form.registration_agreement" />
        </el-col>
      </el-form-item>
      <el-form-item label="中国移动认证条款协议的url">
        <el-col :span="4">
          <el-input v-model="form.cmc_terms_agreement" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团说明的url">
        <el-col :span="4">
          <el-input v-model="form.coupon_introduction" />
        </el-col>
      </el-form-item>
      <el-form-item label="金豆兑换说明的url">
        <el-col :span="4">
          <el-input v-model="form.integral_introduction" />
        </el-col>
      </el-form-item>
      <el-form-item label="法律声明的url">
        <el-col :span="4">
          <el-input v-model="form.legal_notice" />
        </el-col>
      </el-form-item>
      <el-form-item label="隐私协议的url">
        <el-col :span="4">
          <el-input v-model="form.privacy_agreement" />
        </el-col>
      </el-form-item>
      <el-form-item label="icp备案信息">
        <el-col :span="4">
          <el-input v-model="form.record" />
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">Create</el-button>
        <el-button @click="onCancel">Cancel</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getInfo, editInfo } from '@/api/system'
import { Message } from 'element-ui'

export default {
  data() {
    return {
      form: {
        record: '',
        help: '',
        advance: '',
        customer_wechat: '',
        customer_qq: '',
        customer_service: '',
        return_protocol: '',
        refund_protocol: '',
        coupon_protocol: '',
        about_us: '',
        download_Android: '',
        download_iOS: '',
        coupon_bot_rate: '',
        coupon_expire: '',
        exchange_rate: '',
        tbk_rebate_rate: '',
        tbk_parent_rate: '',
        tbk_sub_rate: '',
        rebate_rate: '',
        parent_rate: '',
        sub_rate: '',
        alibaba_price: '',
        description: '',
        keywords: '',
        title_suffix: '',
        title: '',
        order_info: '',
        default_post_fee: 6.0,
        service_rate: '',
        registration_agreement: '',
        cmc_terms_agreement: '',
        coupon_introduction: '',
        integral_introduction: '',
        legal_notice: '',
        privacy_agreement: '',
        coupon_delay: 600,
        userback:'',
        userwin: '',
      }
    }
  },
  created() {
    this.getSystem()
  },
  methods: {
    getSystem() {
      getInfo({ id: 1 }).then(resp => {
        const { data } = resp
        this.form = {
          id: 1,
          exchange_rate: data.exchange_rate,
          coupon_expire: data.coupon_expire,
          coupon_bot_rate: data.coupon_bot_rate,
          alibaba_price: data.alibaba_price,
          tbk_rebate_rate: data.tbk_rebate_rate,
          tbk_parent_rate: data.tbk_parent_rate,
          tbk_sub_rate: data.tbk_sub_rate,
          rebate_rate: data.rebate_rate,
          parent_rate: data.parent_rate,
          sub_rate: data.sub_rate,
          title: data.title,
          title_suffix: data.title_suffix,
          keywords: data.keywords,
          description: data.description,
          record: data.record,
          help: data.help,
          advance: data.advance,
          customer_wechat: data.customer_wechat,
          customer_qq: data.customer_qq,
          customer_service: data.customer_service,
          return_protocol: data.return_protocol,
          refund_protocol: data.refund_protocol,
          coupon_protocol: data.coupon_protocol,
          about_us: data.about_us,
          download_Android: data.download_Android,
          download_iOS: data.download_iOS,
          default_post_fee: data.default_post_fee,
          order_info: data.order_info,
          service_rate: data.service_rate,
          registration_agreement: data.registration_agreement,
          cmc_terms_agreement: data.cmc_terms_agreement,
          coupon_introduction: data.coupon_introduction,
          integral_introduction: data.integral_introduction,
          legal_notice: data.legal_notice,
          privacy_agreement: data.privacy_agreement,
          coupon_delay: data.coupon_delay,
          userback:data.userback,
          userwin:data.userwin
        }
      }).catch(error => {
        Message({
          message: error.response.data.errmsg,
          type: 'error',
          duration: 5 * 1000
        })
      })
    },
    onSubmit() {
      editInfo(this.form).then(() => {
        this.$notify({
          title: '编辑成功',
          type: 'success',
          message: '编辑成功',
          duration: 2000
        })
        this.getSystem()
      }).catch(error => {
        this.$notify({
          title: '编辑失败',
          type: 'error',
          message: error.errmsg,
          duration: 2000
        })
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

